package cn.tedu.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestFilter implements Filter {
    public TestFilter() {
    	System.out.println("TestFilter.Constructor()");
    }
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub
		System.out.println("TestFilter.init(filterConfig)");
	}

	
	@Override          
	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
			throws IOException, ServletException {
		System.out.println("TestFilter.doFilter()---begin");
		HttpServletRequest request=(HttpServletRequest)servletRequest;
		HttpServletResponse response=(HttpServletResponse)servletResponse;
		//if(过滤条件) {
			//有下一个过滤器,则调用下一个过滤器,如果没有下一个过滤器,则请求目标资源
			filterChain.doFilter(servletRequest, servletResponse);
		//}
		System.out.println("TestFilter.doFilter()---end");
	}
	
	@Override
	public void destroy() {
		System.out.println("TestFilter.destroy()");
	}


}
